singleApp.controller('getsmsCtrl', ['$http', '$scope', '$interval', function ($http, $scope, $interval) {
    $scope.vm = { phone: "", sms: "", pas: "", conpas: "", id: 0 };
    $scope.btn_could_click = true;
    $scope.remain_seconds = 60;

    $scope.getsms = function () {
        if ($scope.vm.phone == undefined || $scope.vm.phone == "") {
            layer.msg("请输入11位手机号 !");
            return;
        }

        if ($scope.btn_could_click == false)
            return;

        var api_url = window.singleConfig.rootUrl + 'api/user/AuthService/smsSend';
        layer.load(2);
        $http({
            method: 'POST',
            url: api_url,
            data: $.param($scope.vm),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        })
        .then(function (result) {
            var data = result.data;
            if (data.code == "success") {
                layer.closeAll();
                layer.msg("发送成功!");
                $scope.btn_could_click = false;
                $scope.remain_seconds = 60;
                $scope.vm.id = data.id;

                var obj = $interval(function () {
                    if ($scope.remain_seconds == 1) {
                        $scope.btn_could_click = true;
                        $interval.cancel(obj);
                    }
                    else {
                        $scope.remain_seconds--;
                        $("#spanRemainSeconds").html($scope.remain_seconds);
                    }
                }, 1000);
            }
            else {
                layer.closeAll();
                layer.msg(data.message);
            }
        }, function (data) {
            layer.closeAll();
            layer.msg("发送失败!");
        });
    };


    $scope.submit = function () {
        if ($scope.vm.phone == undefined || $scope.vm.phone == "") {
            layer.msg("请输入11位手机号 !");
            return;
        }
        if ($scope.vm.sms == undefined || $scope.vm.sms == "") {
            layer.msg("请输入短信验证码 !");
            return;
        }


        if ($scope.vm.pas == "") {
            layer.msg("请输入新密码 !");
            return;
        }

        //if ($scope.vm.pas == "" || $scope.vm.conpas == "") {
        //    layer.msg("请输入密码 !");
        //    return;
        //}

        //if ($scope.vm.pas != $scope.vm.conpas) {
        //    layer.msg("两次密码不一致 !");
        //    return;
        //}

        var api_url = window.singleConfig.rootUrl + 'api/user/AuthService/smsPost';
        layer.load(2);
        $http({
            method: 'POST',
            url: api_url,
            data: $.param($scope.vm),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        })
        .then(function (result) {
            var data = result.data;
            if (data.code == "success") {
                layer.closeAll();
                layer.msg("修改成功");
                setTimeout(function () {
                    location.href = window.singleConfig.rootUrl + "auth/login";
                }, 500);
            }
            else {
                layer.closeAll();
                layer.msg(data.message);
            }
        }, function (data) {
            layer.msg("系统错误!");
        });
    }

}]);